import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
class Base():
    def __init__(self,driver):
        self.driver = driver

    def open(self,url):
        self.driver.get(url)

    def find_element(self,loc):
        return self.driver.find_element(*loc)

    def click(self,loc):
        self.find_element(loc).click()

    def text(self,loc):
        return self.find_element(loc).text

    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)

    def jietu(self):
        et = time.strftime("%Y%m%d%H%M%S", time.localtime())
        self.driver.save_screenshot(et+'.png')

    def switch_window(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])

    def scrollTo_H(self):
        self.driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')

    def scrollTo_x(self,x):
        self.driver.execute_script(f'window.scrollTo(0,{x})')

    def frame(self,loc):
        self.driver.switch_to.frame(self.find_element(loc))

    def frame_quit(self):
        self.driver.switch_to.default_content()

    def accept(self):
        self.driver.switch_to.alert.accept()

    def dismiss(self):
        self.driver.switch_to.alert.dismiss()

    def send_accept(self,info):
        prompt = self.driver.switch_to.alert
        prompt.send_keys(info)
        prompt.accept()

    def send_dismiss(self,info):
        prompt = self.driver.switch_to.alert
        prompt.send_keys(info)
        prompt.dismiss()

    def double_click(self,loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).perform()

    def three_click(self, loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).click(self.find_element(loc)).perform()

    def context_click(self,loc):
        ActionChains(self.driver).context_click(self.find_element(loc)).perform()

    def move_to_element(self,loc):
        ActionChains(self.driver).move_to_element(self.find_element(loc)).perform()

    def drag_and_drop(self,loc,x,y):
        ActionChains(self.driver).drag_and_drop_by_offset(self.find_element(loc),x,y).perform()

    def click_and_hold(self,loc):
        ActionChains(self.driver).click_and_hold(self.find_element(loc)).perform()

    def keys_enter(self,loc):
        self.send_keys(loc,Keys.ENTER)

    def keys_tab(self,loc):
        self.send_keys(loc,Keys.TAB)
    def Keys_Delete(self,loc):
        self.send_keys(loc,Keys.DELETE)
    def Keys_BackSpace(self,loc):
        self.send_keys(loc,Keys.BACKSPACE)
    def Keys_Space(self,loc):
        self.send_keys(loc,Keys.SPACE)
    def Keys_Home(self,loc):
        self.send_keys(loc,Keys.HOME)
    def Keys_Up(self,loc):
        self.send_keys(loc,Keys.UP)
    def Keys_Right(self,loc):
        self.send_keys(loc,Keys.RIGHT)
    def Keys_Left(self,loc):
        self.send_keys(loc,Keys.LEFT)
    def Keys_Control(self,loc):
        self.send_keys(loc,Keys.CONTROL)